/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package AdminOperations;

import CRUD.ThemeHome;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import xmlMapping.Theme;

/**
 *
 * @author ABDELMOHSEN
 */
public class AdminManageTheme {
    public void changeThemeOnFile(int themeID){
        File f=new File("./ForumConfig.txt");
        try {
            DataInputStream din = new DataInputStream(new FileInputStream(f));
            try {
                int theme=din.readInt();
                int registration=din.readInt();
                DataOutputStream dOut = new DataOutputStream(new FileOutputStream(f));
                dOut.writeInt(themeID);
                dOut.writeInt(registration);
            } catch (IOException ex) {
                Logger.getLogger(AdminManageTheme.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (FileNotFoundException ex) {
            try {
                DataOutputStream dOut = new DataOutputStream(new FileOutputStream(f));
                dOut.writeInt(themeID);
                dOut.writeInt(1);
            } catch (Exception ex1) {
                Logger.getLogger(AdminManageTheme.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }
    }
    public List getAllThemes(){
        ThemeHome thH=new ThemeHome();
        List l=thH.findAll();
        return l;
    }
    public int getSelectedThemeFromFile(){
        int theme=0;
        File f=new File("./ForumConfig.txt");
        try {
            DataInputStream din = new DataInputStream(new FileInputStream(f));
            try {
                theme=din.readInt();
                int registration=din.readInt();
            } catch (IOException ex) {
                Logger.getLogger(AdminManageTheme.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (FileNotFoundException ex) {
            try {
                DataOutputStream dOut = new DataOutputStream(new FileOutputStream(f));
                dOut.writeInt(1);
                dOut.writeInt(1);
            } catch (Exception ex1) {
                Logger.getLogger(AdminManageTheme.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }
        return theme;
    }

    /*public static void main(String[] args){
        AdminManageTheme test=new AdminManageTheme();
        //Iterator<Theme> it=test.getAllThemes().iterator();
        //System.out.println(it.next().getName());
        //test.changeThemeOnFile(1);
        //int th=test.getSelectedThemeFromFile();
        //System.out.println(th);
    }*/
    
}
